//
//  BaseViewController.m
//  CROSBY
//
//  Created by Harvey on 2017/10/3.
//  Copyright © 2017年 Haley. All rights reserved.
//

#import "BaseViewController.h"
#import "BluetoothManager.h"

#import "UIImage+Extension.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.showBackBtn = YES;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initBgView];
    
    NSArray *viewControllers = self.navigationController.viewControllers;
    if (viewControllers.count > 1 && self.showBackBtn) {
        UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 36)];
        UIImage *backImage = [[UIImage imageNamed:@"navigation_back"] imageWithColor:[UIColor whiteColor]];
        [backBtn setImage:backImage forState:UIControlStateNormal];
        backBtn.showsTouchWhenHighlighted = YES;
        [backBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
        self.navigationItem.leftBarButtonItem = backItem;
    }
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setupLanguage) name:kAppLanguageChangedNotification object:nil];
}
    
// 子类重写
- (void)setupLanguage
{
    
}

- (void)initBgView
{
    UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
    bgImageView.contentMode = UIViewContentModeScaleToFill;
    
    UIImage *bgImage = [UIImage imageNamed:@"gw_ic_bg"];
    if ([BluetoothManager standardManager].peripheralType == BTPeripheralTypeCrosby) {
        bgImage = [UIImage imageNamed:@"ic_bg"];
    }
    bgImageView.image = bgImage;
    
    [self.view insertSubview:bgImageView atIndex:0];
}

- (void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}

//// 支持设备自动旋转
//- (BOOL)shouldAutorotate
//{
//    return YES;
//}
//
//// 支持竖屏显示
//- (UIInterfaceOrientationMask)supportedInterfaceOrientations
//{
//    return UIInterfaceOrientationMaskPortrait;
//}

@end
